const app = getApp();
Page({

    /**
     * 页面的初始数据
     */
    data: {
        refund_id: '',
        type: '',
        refund: {},
        detail_array: [],
        pic_list: []
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        var refund_id = options.refund_id;
        var type = options.type;
        var self = this;
        wx.getStorage({
            key: 'key',
            success: res => {
                self.setData({
                    key: res.data
                })
            }
        })
        self.setData({
            refund_id: refund_id,
            type: type
        })
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {
        var self = this;
        var act = '';
        var op = '';
        var type_id = '';
        if (self.data.type == 'refund') {
            act = 'member_refund';
            op = 'get_refund_info';
            type_id = 'refund_id';
        } else if (self.data.type == 'return') {
            act = 'member_return';
            op = 'get_return_info';
            type_id = 'return_id';
        }
        wx.request({
            url: app.globalData.ApiUrl + '/index.php?act=' + act + '&op=' + op,
            data: {
                key: self.data.key,
                [type_id]: self.data.refund_id
            },
            method: 'GET',
            dataType: 'json',
            success: res => {
                if (res.data.code == 200) {
                    var data = res.data.datas;
                    if (self.data.type == 'refund') {
                        self.setData({
                            detail_array: data.detail_array,
                            pic_list: data.pic_list,
                            refund: data.refund
                        })
                    } else if (self.data.type == 'return') {
                        self.setData({
                            detail_array: data.detail_array,
                            pic_list: data.pic_list,
                            refund: data.return_info
                        })
                    }


                } else {
                    wx.showToast({
                        title: res.data.datas.error,
                        icon: 'none'
                    })
                }
            }
        })
    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})